// pages/equipStatis/equipStatis.js
const app = getApp()
const lbbService = require('../service/service.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    chairStatus: [{
        value: 0,
        name: '确认丢失',
        checked: true,
        color:'#8290DD',
      },
      {
        value: 1,
        name: '疑似丢失',
        checked: false,
        color:'#8290DD',
      },
      {
        value: 2,
        name: '购买下线',
        checked: false,
        color:'#8290DD',
      },
      {
        value: 3,
        name: '赔偿下线',
        checked: false,
        color:'#8290DD',
      },
      {
        value: 4,
        name: '恶意不归还',
        checked: false,
        color:'#8290DD',
      },
      {
        value: 5,
        name: '赔偿未支付',
        checked: false,
        color:'#8290DD',
      }
    ],
    hosId:"",
    firstCount:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this
    that.setData({
      hosId: options.hospitalId,
      hosName: options.hospitalName,
      scrollHeight: app.getScrollHeight(0)
    })
    
    that.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },
  typeChange: function(e) {
    let that = this
    console.log(e,that.data.equipList)
    let index = e.detail.value
    let equips = that.data.equipList[index].equips
    that.setData({
      equips: equips
    })
  },
  getList: function() {
    let that = this
    lbbService.getHospitalEquip({
      hospitalId: that.data.hosId
    }, function(res) {
      let equipList = [{
        num: res.data.loseEqu,
        equips: res.data.loseEquHandleInfoList
        }, {
          num: res.data.isLoseEqu,
          equips: res.data.isLoseEquHandleInfoList
        },
        {
          num: res.data.byEqu,
          equips: res.data.byEquHandleInfoList
        }, {
          num: res.data.demaedEqu,
          equips: res.data.demaedEquHandleInfoList
        }, {
          num: res.data.noBack,
          equips: res.data.noBackHandleInfoList
        },{
            num:res.data.unpaidEqu,
            equips: res.data.unpaidEquHandleInfoList?res.data.unpaidEquHandleInfoList:[]
        }
      ]
      that.setData({
        equipList: equipList,
        equips: equipList[0].equips
      })
      that.setNum()
    })
    var hosId=that.data.hosId
    console.log(hosId)
    lbbService.getFirstLockCount({hosId},function(res){
        that.setData({
          firstCount:res.data
        })
    })
  },
  setNum: function() {
    let that = this
    let equipList = that.data.equipList
    let chairStatus = that.data.chairStatus
    for (let i = 0; i < 6; i++) {
      chairStatus[i].num = equipList[i].num
    }
    that.setData({
      chairStatus: chairStatus
    })
  }
})